/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.unittests.struts.service.beans;

import opiam.admin.faare.PropertiesManager;
import opiam.admin.faare.struts.service.beans.JBMenuElement;
import opiam.admin.faare.unittests.TestResult;
import opiam.admin.faare.unittests.TestUtils;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.log4j.Logger;


/**
 * Test of the JBMenuElement class.
 */
public class JBMenuElementTest extends TestCase
{
    /** Instance of logger. */
    private static Logger _logger = Logger.getLogger(JBMenuElementTest.class);

    /** Instance of the trace class. */
    private static TestUtils _test = new TestUtils(_logger);

    /** Instance of JBMenuElement. */
    private JBMenuElement jbMenuElement = new JBMenuElement();

    /**
     * Creates a new JBMenuElementTest object.
     *
     * @param arg0  Parameter.
     */
    public JBMenuElementTest(String arg0)
    {
        super(arg0);

        try
        {
            PropertiesManager.getInstance();
        }
        catch (Exception e)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("JBMenuElementTest constructor error\n");
            msg.append(e.toString());
            _test.displayResultFailure(msg.toString());
        }
    }

    /**
     * Method of the tests suite.
     *
     * @return Tests result.
     */
    public static Test suite()
    {
        TestSuite suite = new TestSuite();

        suite.addTest(new JBMenuElementTest("testBegin"));

        suite.addTest(new JBMenuElementTest("testGetName"));
        suite.addTest(new JBMenuElementTest("testGetShowicon"));
        suite.addTest(new JBMenuElementTest("testUseIcon"));

        suite.addTest(new JBMenuElementTest("testEnd"));

        return suite;
    }

    /**
     * Main method of the test class.
     *
     * @param args  Sets of the parameters.
     */
    public static void main(String[] args)
    {
        junit.textui.TestRunner.run(suite());
    }

    /**
     * Method to indicate the beginning of the class test.
     *
     */
    public static void testBegin()
    {
        //  To initialize the tests statement
        TestResult.getInstance().setInitiator("JBMenuElementTest");

        _test.displayHeaderClass("JBMenuElementTest");
        assertTrue(true);
    }

    /**
     * Method to indicate the end of the class test.
     *
     */
    public static void testEnd()
    {
        _test.displayFooterClass(null);
        assertTrue(true);

        // To display the tests statement
        _test.displayTestStatement("JBMenuElementTest");
    }

    /**
     * Test the methods: setName and getName.
     *
     */
    public void testGetName()
    {
        _test.displayHeaderMethod("testGetName");

        try
        {
            String expected = "homepage";
            jbMenuElement.setName("homepage");
            _test.displayMsg("Expected : homepage");

            String result = jbMenuElement.getName();

            if (expected.equals(result))
            {
                _test.displayResultSuccess(null);
            }
            else
            {
                _test.displayResultFailure("getName : " + result);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testGetName");
    }

    /**
     * Test the methods: setShowicon and getShowicon.
     *
     */
    public void testGetShowicon()
    {
        _test.displayHeaderMethod("testGetShowicon");

        try
        {
            String expected = "true";
            jbMenuElement.setShowicon("true");
            _test.displayMsg("Expected : true");

            String result = jbMenuElement.getShowicon();

            if (expected.equals(result))
            {
                _test.displayResultSuccess(null);
            }
            else
            {
                _test.displayResultFailure("getShowicon : " + result);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testGetShowicon");
    }

    /**
     * Test the methods: UseIcon.
     *
     */
    public void testUseIcon()
    {
        _test.displayHeaderMethod("testUseIcon");

        try
        {
            boolean expected = true;
            jbMenuElement.setShowicon("true");

            boolean result = jbMenuElement.useIcon();

            if (expected == result)
            {
                _test.displayResultSuccess(null);
            }
            else
            {
                _test.displayResultFailure(null);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testUseIcon");
    }
}
